setwd("/home1/30/jc227089/SRE/equil/PBS")

tt<-((1:21)-1)/20
dct<-((1:6)-1)/10

script.file<-'/home1/30/jc227089/evo-dispersal/SRE/Equilibrium_PVA.R'

for (ii in 1:length(tt)) {
	for (jj in 1:length(dct)){
		fid<-(ii-1)*length(dct)+jj #file.ID
		##create the sh file
		zz = file(paste("SREequil", fid,'.sh',sep=''),'w')
		cat('##################################\n',file=zz)
		cat('#!/bin/sh\n',file=zz)
		cat('cd $PBS_O_WORKDIR\n',file=zz)
		cat("R CMD BATCH --no-save --no-restore '--args rr=5 file.ID=",fid, " hv=", tt[ii], " dc=", dct[jj],"' ", sep="", file=zz)
		cat(script.file, " ", paste("SREequil", fid,'.Rout',sep=''), "\n", sep="",file=zz)
		cat('##################################\n',file=zz)
		close(zz)
			
		#submit the job
		system(paste("qsub -m n ", paste("SREequil", fid,".sh",sep=""),sep=""))
	}
}
